<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> -->
    <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>

<body>
    <div id="app">
        <!-- 遍历数组 -->
        <!-- <ul>
            <li v-for="(abc,index) in nameArr" v-bind:key="abc.id">{{index}}--{{abc.name}}</li>
        </ul> -->
        <!-- 遍历对象 -->
        <!-- <p v-for="(value,key,index) in userObj" :key="key">{{key}}--{{value}}--{{index}}</p> -->

        <!-- 遍历字符串 -->
        <!-- <ul>
            <li v-for="(item,index) in str" :key="index">{{index}}--{{item}}</li>
        </ul> -->
        <!-- 遍历数字 -->
        <!-- <ul>
            <li v-for="item in num" :key="item">{{item}}</li>
        </ul> -->

        <!-- 嵌套遍历 -->
        <ul>
            <li v-for="item in boyArr" :key="item.id">
                <p>{{item.name}}</p>
                <ul v-for="v in item.children" :key="v.id">
                    <li>{{v.name}}</li>
                </ul>
            </li>
        </ul>
    </div>
</body>

</html>
<script>

    // v-for 一般结合key 属性使用
    // key 属性作用: 是一个唯一索引,用来标记该标签的唯一性
    // 当进行虚拟dom进行比较的时候,新的dom 和旧的虚拟dom 比较, 如果标签有key属性, 则可以提高比较效率
    // diff 算法 同层比较, 可以提高diff 算法的比较效率



    const { createApp } = Vue;
    const vm = createApp({
        data() {
            return {
                message1: 'Hello',
                nameArr: [
                    {
                        id: 1,
                        name: '及时雨-宋江'
                    },
                    {
                        id: 2,
                        name: '玉麒麟-卢俊义'
                    },
                    {
                        id: 3,
                        name: '智多星-吴用'
                    }
                ],
                userObj: {
                    username: '黑旋风-李逵',
                    age: 40
                },
                str: 'abcdefg',
                num: 10,
                boyArr: [
                    {
                        id: 1,
                        name: '郭德纲',
                        children: [
                            {
                                id: 1,
                                name: '郭麒麟'
                            },
                            {
                                id: 2,
                                name: '陶阳'
                            }
                        ]
                    },
                    {
                        id: 2,
                        name: '于谦',
                        children: [
                            {
                                id: 1,
                                name: '岳云鹏'
                            },
                            {
                                id: 2,
                                name: '孙越'
                            }
                        ]
                    }
                ]

            }
        }
    }).mount('#app') 
</script>